﻿using MongoDB.Driver;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.SharedEntities.EsgResearch;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.EsgResearchProfileLogic
{
    public class EsgResearchProfileCommand : SyncEsgCommand<EsgResearchProfile>
    {
        private readonly IMongoCollection<EsgResearchProfile> esgResearchProfileMongoCollection;

        public EsgResearchProfileCommand(IMongoCollection<EsgResearchProfile> esgResearchProfileMongoCollection, ILogger logger) : base(logger)
        {
            this.esgResearchProfileMongoCollection = esgResearchProfileMongoCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds, Guid? additionalDiscriminator = null)
        {
            return await esgResearchProfileMongoCollection.DeleteManyAsync(x => companiesIds.Contains(x.Id)).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<EsgResearchProfile> entities)
        {
            await esgResearchProfileMongoCollection.InsertManyAsync(entities).ConfigureAwait(false);
        }
    }
}
